package com.ydche.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class MyTime {
    public static String getCurrentDateTime() {
        Date day=new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df.format(day);
    }

    public static Date transToDate(String dateStr) {
        Date date = null;
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
        try {
            date = dft.parse(dateStr);
        } catch (ParseException e) {

        }
        return date;
    }

    public static Date addYear(Date date, int years){
        if(date==null){
            return null;
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.YEAR, years);
        return cal.getTime();
    }

    public static String DateFormat(Date date){
        if (date == null){
            return "";
        }
        return new SimpleDateFormat("yyyy-MM-dd").format(date);
    }
}
